package com.blb.thread;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 原子类案例
 */
public class AtomicDemo {

//    public static long count = 0;
    public static AtomicLong count = new AtomicLong(0);

    public static void main(String[] args) throws InterruptedException {
        //1000个线程执行自增
        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
//                count++;
                count.getAndIncrement();
            }).start();
        }
        Thread.sleep(1000);
        System.out.println("count = " + count);
    }
}
